package com.distributer.order.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.distributer.order.event.OrderItemAddFinishedEvent;
import com.distributer.order.service.OrderService;

@Component
@Transactional
public class OrderListener {

	@Autowired
	private OrderService orderService;
	
	@EventListener
	@Async
	public void handOrderItemCreateFinishedEvent(OrderItemAddFinishedEvent orderItemAddFinishedEvent){
		String orderNo = orderItemAddFinishedEvent.getOrderNo();
		boolean result = orderItemAddFinishedEvent.isAddOrderItemResult();
		orderService.updateOrderStatusByOrderItemCreateResult(orderNo,result);
	}
}
